﻿package kizzo.utils 
{
	import flash.display.DisplayObject;
	import flash.filters.ColorMatrixFilter;
	import flash.utils.*;

	
	public class ColorMatrixFilterTweener extends BaseTweener
	{
		private var start_matrix:Array;
		private var end_matrix:Array;
		private var step_matrix:Array;
		
		private var tween_obj:DisplayObject;
		
		public function ColorMatrixFilterTweener(start_matrix:Array, end_matrix:Array, steps:uint, tween_obj:DisplayObject) 
		{			
			this.start_matrix = start_matrix;
			this.end_matrix = end_matrix;
			this.step_matrix = [];
			
			this.tween_obj = tween_obj;
			
			super(steps);
		}
		
		override protected function init():void
		{
			for (var i:uint = 0; i < this.start_matrix.length; i++)
				this.step_matrix[i] = (this.end_matrix[i] - this.start_matrix[i]) / this.steps;
		}
			
		override protected function set_current(step:uint):void
		{			
			var current_array:Array = [];
			for (var i:uint = 0; i < this.start_matrix.length; i++)
				current_array[i] = this.start_matrix[i] + this.step_matrix[i] * step;	
				
			this.tween_obj.filters = [new ColorMatrixFilter(current_array)];			
		}
	}
	
}